<!DOCTYPE html>
<html>
 <head>
  <title> new document </title>  
  <meta http-equiv="Content-Type" content="text/html; charset=utf8"/>   
  <script type="text/javascript"> 
  
      window.onload = function(){
      	var trs = document.getElementsByTagName('tr');
      	mouses(trs);
      }
      
    function mouses(trs){      
       for(var i = 1; i < trs.length; i++){
            trs[i].onmouseover = function(){
                 this.style.backgroundColor = "#f2f2f2";
            }
            trs[i].onmouseout = function(){
                 this.style.backgroundColor = "#fff";
            }
      }
 	}
      // 编写一个函数，供添加按钮调用，动态在表格的最后一行添加子节点；
     function addtrs(){
     	var tr1=document.getElementById("table");
     	var newtr=document.createElement("tr");
     	var newtd1=document.createElement("td");
     	var newtd2=document.createElement("td");
     	var newtd3=document.createElement("td");
     	newtd1.innerHTML="xh00";
     	newtd2.innerHTML="date";
     	newtd3.innerHTML="<a href=\"javascript:;\" onclick=\"removetr(this)\" >删除</a>";
     	newtr.appendChild(newtd1);
     	newtr.appendChild(newtd2);
     	newtr.appendChild(newtd3);
     	tr1.appendChild(newtr);
     	var trs = document.getElementsByTagName('tr');
        mouses(trs);
    		
   	 }
     // 创建删除函数
     function removetr(obj){
     	var tr=obj.parentNode.parentNode;
     	tr.parentNode.removeChild(tr);
     }

  </script> 
 </head> 
 <body> 
	   <table border="1" width="50%" id="table">
	   <tr>
		<th>学号</th>
		<th>姓名</th>
		<th>操作</th>
	   </tr>  

	   <tr>
		<td>xh001</td>
		<td>王小明</td>
		<td><a href="javascript:;" onclick="removetr(this)" >删除</a></td>   <!--在删除按钮上添加点击事件  -->
	   </tr>

	   <tr>
		<td>xh002</td>
		<td>刘小芳</td>
		<td><a href="javascript:;" onclick="removetr(this)">删除</a></td>   <!--在删除按钮上添加点击事件  -->
	   </tr>  

	   </table>
	   <input type="button" value="添加一行" onclick="addtrs()" />   <!--在添加按钮上添加点击事件  -->
 </body>
</html>